package cn.schoolwow.workflow.test.module.analyzeWorkReport.audit.single.start;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.dto.FlowContextDataRange;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.QuickWorkFlow;
import cn.schoolwow.workflow.domain.instance.StartWorkFlowRequest;
import cn.schoolwow.workflow.entity.WorkFlowInstance;

public class StartAnalyzeWorkReportAuditFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QuickWorkFlow quickWorkFlow = flowContext.checkInstanceData(QuickWorkFlow.class);
        String deployName = (String) flowContext.checkData("deployName");
        BusinessFlow beforeStartWorkFlow = flowContext.getData("beforeStartWorkFlow", BusinessFlow.class);

        StartWorkFlowRequest startWorkFlowRequest = new StartWorkFlowRequest();
        startWorkFlowRequest.definitionName = deployName;
        startWorkFlowRequest.instanceName = "分析工作报告审批实例";
        startWorkFlowRequest.contextData.put("firstAuditUserId", 1);
        startWorkFlowRequest.contextData.put("secondAuditUserId", 2);
        startWorkFlowRequest.contextData.put("密码", "123456");
        startWorkFlowRequest.initiator = "张三";
        startWorkFlowRequest.carbonCopyList.add("孙七");
        flowContext.putInstanceData(startWorkFlowRequest, FlowContextDataRange.ContextThreadLocal);
        if(null!=beforeStartWorkFlow){
            beforeStartWorkFlow.executeBusinessFlow(flowContext);
        }

        WorkFlowInstance workFlowInstance = quickWorkFlow.startWorkFlow(startWorkFlowRequest);
        flowContext.putInstanceData(workFlowInstance);
    }

    @Override
    public String name() {
        return "分析工作报告-启动工作流";
    }
}
